package com.mrd.gtimp.test.entity;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

/**
 * <p>
 * application name: fsla
 * <p>
 * copyright: Copyright@2012 明睿达科技有限公司
 */
/**
 * 栏目类
 * @author qiul
 */
@Entity(name = "LA_COLUMN")
public class Column implements Serializable, Comparable<Column> {

	private static final long	serialVersionUID	= 1L;

	@Id
	@GeneratedValue(generator = "columnid")
	@GenericGenerator(name = "columnid", strategy = "uuid")
	private String	          id;
	@javax.persistence.Column(name = "C_NAME", nullable = false)
	private String	          c_name;
	@javax.persistence.Column(name = "MARK")
	private String	          mark;
	@javax.persistence.Column(name = "C_TYPE", nullable = false)
	private String	          c_type;
	@javax.persistence.Column(name = "C_STATE", nullable = false)
	private String	          c_state;
	@javax.persistence.Column(name = "REG_USER_NAME", nullable = false, updatable = false)
	private String	          req_user_name;
	@javax.persistence.Column(name = "REG_DATE", updatable = false)
	private Date	          req_date;
	@javax.persistence.Column(name = "MOD_USER_NAME")
	private String	          mod_user_name;
	@javax.persistence.Column(name = "MOD_DATE", nullable = false)
	private Date	          mod_date;
	@javax.persistence.Column(name = "c_order", nullable = false)
	private Integer	          order;

	@javax.persistence.Column(name = "pid")
	private String	          pid;

	/**
	 * 子类集合
	 */
	@OneToMany(cascade = CascadeType.ALL)
	@LazyCollection(LazyCollectionOption.FALSE)
	@JoinColumn(name = "pid")
	private List<Column>	  childColumns;
	/**
	 * 在树中是否为父节点
	 */
	// 指定该字段为非数据库字段
	@Transient
	private String	          isParent;
	/**
	 * 在做成树时是否默认打开
	 */
	@Transient
	private String	          open;

	@Transient
	private int	              level;
	@Transient
	private String	          parent;
	@Transient
	private String	          isLeaf;
	@Transient
	private String	          expanded;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getC_name() {
		return c_name;
	}

	public void setC_name(String c_name) {
		this.c_name = c_name;
	}

	public String getMark() {
		return mark;
	}

	public void setMark(String mark) {
		this.mark = mark;
	}

	public String getC_type() {
		return c_type;
	}

	public void setC_type(String c_type) {
		this.c_type = c_type;
	}

	public String getC_state() {
		return c_state;
	}

	public void setC_state(String c_state) {
		this.c_state = c_state;
	}

	public String getReq_user_name() {
		return req_user_name;
	}

	public void setReq_user_name(String req_user_name) {
		this.req_user_name = req_user_name;
	}

	public Date getReq_date() {
		return req_date;
	}

	public void setReq_date(Date req_date) {
		this.req_date = req_date;
	}

	public String getMod_user_name() {
		return mod_user_name;
	}

	public void setMod_user_name(String mod_user_name) {
		this.mod_user_name = mod_user_name;
	}

	public Date getMod_date() {
		return mod_date;
	}

	public void setMod_date(Date mod_date) {
		this.mod_date = mod_date;
	}

	public String getOpen() {
		return open;
	}

	public void setOpen(boolean open) {
		this.open = String.valueOf(open);
	}

	public String getIsParent() {
		return isParent;
	}

	public void setIsParent(boolean isParent) {
		this.isParent = String.valueOf(isParent);
	}

	public String getPid() {
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	public List<Column> getChildColumns() {
		return childColumns;
	}

	public void setChildColumns(List<Column> childColumns) {
		this.childColumns = childColumns;
	}

	public void setIsParent(String isParent) {
		this.isParent = isParent;
	}

	public void setOpen(String open) {
		this.open = open;
	}

	@Override
	public int compareTo(Column o) {
		int i = this.order.compareTo(o.order);
		if(i == 0) {
			i = this.c_name.compareTo(c_name);
		}
		return i;
	}

	public Integer getOrder() {
		return order;
	}

	public void setOrder(Integer order) {
		this.order = order;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public String getParent() {
		return parent;
	}

	public void setParent(String parent) {
		this.parent = parent;
	}

	public String getIsLeaf() {
		return isLeaf;
	}

	public void setIsLeaf(String isLeaf) {
		this.isLeaf = isLeaf;
	}

	public String getExpanded() {
		return expanded;
	}

	public void setExpanded(String expanded) {
		this.expanded = expanded;
	}

	@Override
	public String toString() {
		return "Column [id=" + id + ", c_name=" + c_name + ", mark=" + mark + ", c_type=" + c_type
		        + ", c_state=" + c_state + ", req_user_name=" + req_user_name + ", req_date="
		        + req_date + ", mod_user_name=" + mod_user_name + ", mod_date=" + mod_date
		        + ", order=" + order + ", pid=" + pid + ", childColumns=" + childColumns
		        + ", isParent=" + isParent + ", open=" + open + "]";
	}

}
